package com.inspur.sc.springboot.dao;

import com.inspur.sc.springboot.entity.SysMenu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SysMenuDao extends JpaRepository<SysMenu,Integer> {

    @Query(value = "select DISTINCT m.* from sys_menu m " +
            "LEFT JOIN sys_permission_group spg on spg.sys_permission_id=m.id " +
            "LEFT JOIN sys_group_role sgr on spg.sys_group_id=sgr.sys_group_id " +
            "LEFT JOIN sys_role_user sru on sru.sys_role_id=sgr.sys_role_id " +
            "where sru.sys_user_id=?1 and m.isDisplay='yes' and spg.type='m' ",nativeQuery = true)
    List<SysMenu> findSysMenuByUserId(Integer userId);


    @Query(value = "select * from sys_menu m where m.pid=0",nativeQuery = true)
    List<SysMenu> findSysMenuIsParent();
}
